package com.itheima.a02jdk8datedemo;

import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Set;

public class InstantDemo1 {
    public static void main(String[] args) {
        //获取当前时间的Instant对象（标准时间）
        Instant now = Instant.now();
        System.out.println(now);
        //根据（秒/毫秒/纳秒）获取Instant对象
        Instant instant = Instant.ofEpochMilli(2000L);
        System.out.println(instant);
        Instant instant2 = Instant.ofEpochSecond(20L);
        System.out.println(instant2);
        Instant instant3 = Instant.ofEpochSecond(2L,1000000000L);
        System.out.println(instant3);
        //指定时区
        //打印下所有时区
        Set<String> zoneIds = ZoneId.getAvailableZoneIds();
        System.out.println(zoneIds);
        ZonedDateTime zonedDateTime = Instant.now().atZone(ZoneId.of("Asia/Shanghai"));
        System.out.println(zonedDateTime);
        //判断系统的方法
        boolean before = instant.isBefore(instant2);
        boolean after = instant.isAfter(instant3);
        System.out.println(before);
        System.out.println(after);

        //标准时间对象Instant不会变，会创建一个新的Instant对象来表示增加或减少后的Instant事件对象
        //减少时间系统的方法
        Instant instant1 = instant.minusSeconds(3L);
        System.out.println(instant1);
        //增加时间系统的方法
        Instant instant4 = instant.plusMillis(1000L);
        System.out.println(instant4);
    }
}
